# encoding:utf8
from django import forms
from django.core.validators import RegexValidator

login_form_default_errors = {
    'required': '该字段为必填项',
    'invalid': '输入无效值'
}

phone_regex = RegexValidator(regex=r'^1\d{10}$', message="手机号码输入无效")


class LoginForm(forms.Form):
    username = forms.CharField(max_length=20, label="用户名", required=True,
                               widget=forms.TextInput(attrs={"placeholder": "用户名", "class": "username"}),
                               error_messages=login_form_default_errors)
    password = forms.CharField(max_length=20, label="密码", required=True,
                               widget=forms.PasswordInput(attrs={"placeholder": "密码", "class": "password"}),
                               error_messages=login_form_default_errors)


class RegisterForm(forms.Form):
    username = forms.CharField(max_length=20, label="用户名", required=True,
                               widget=forms.TextInput(attrs={"placeholder": "用户名", "class": "username"}))
    real_name = forms.CharField(max_length=20, label="姓名", required=True,
                                widget=forms.TextInput(attrs={"placeholder": "姓名", "class": "real_name"}))
    password = forms.CharField(max_length=20, label="密码", required=True,
                               widget=forms.PasswordInput(attrs={"placeholder": "密码", "class": "password"}))
    retry_password = forms.CharField(max_length=20, label="确认密码", required=True,
                                     widget=forms.PasswordInput(attrs={"placeholder": "确认密码", "class": "password"}))
    email_address = forms.EmailField(label="邮箱", required=False,
                                     widget=forms.EmailInput(attrs={"placeholder": "邮箱", "class": "email"}))
    mobile_number = forms.CharField(validators=[phone_regex], label="手机号码", required=False,
                                    widget=forms.TextInput(attrs={"placeholder": "手机号码", "class": "mobile_number"}))
